<?php
/** 
 * @package AMFramework
 * @subpackage Core
 * @author Marcu Alexandru
 * @version 1.0 $Build 305b  
 */
defined('_INDEX') or die('Restricted');

class Amfw_Document extends Amfw_Document_Macros implements Amfw_Document_IDocument, Amfw_Document_IMacros
{ ///TODO: Clasa Amfw_Document_Macros ar trebui sa dispara pentru ca nu mai este
  /// folosita decat pentru getContent
	protected $_doctype = 'xhtml1-transitional';
	protected $_title 	= '';
	protected $_meta 	= array();
	protected $_css 	= array();
	protected $_scripts	= array();
	protected $_jshead	= array();
	protected $_navbar	= array();
	
	private $_lang = 'en_GB';
	
	// `Interfete` pentru macro-uri -------------------------------------------
	public function content()
	{
		return $this->getContent();
	}
	public function doctype()
	{
		return Amfw_Html_Document::doctype($this->_doctype);
	}
	public function title()
	{
		return $this->_title;
	}
	public function meta()
	{
		return Amfw_Html_Document::meta($this->_meta);
	}
	public function style()
	{
		return Amfw_Html_Document::stylesheet($this->_css);
	}
	public function scripts()
	{
		return Amfw_Html_Document::javascript($this->_scripts,false);
	}
	public function jscript() {
		$html = '';		
			foreach($this->_jshead as $script) {
			$html .= $script. "\n";
		}		
		return $html;		
	}
	
	public function navbar()
	{
		//var_dump($this->_navbar);
		//return serialize($this->_navbar)
		return Amfw_Html::navbar($this->_navbar);
	}
	// Settere ----------------------------------------------------------------
	public function setDoctype($doctype)
	{
		$this->_doctype = $doctype;
	}
	public function setNavbarItems( $items )
	{
		//TODO: Probably something more high-class implemented here?
		$this->_navbar = $items; //Amfw_Html::navbar( $items  );
	}
	public function setTitle($title = '') 
	{
		if(!empty($title))
		{
			$this->_title = $title;
			return true;
		}
		else return false;
	}
	
	public function setLanguage($lang) {
		$this->_lang = $lang;
	}
	public function getLanguage() {
		return $this->_lang;
	}
	// Addere -----------------------------------------------------------------
	//TODO: Trebuiesc rafinate pentru a putea utiliza Amfw_Html_Document
	public function addStylesheet($cssPath) 
	{
		$this->_css[] = $cssPath;
	}
	public function addScript($js, $isCode = false) 
	{
		if($isCode) 
		{	// If the script contains actual code, it will be echoed automatically
			// TODO: Consider this behaviour;
			$this->_jshead[] = $js;
		}
		else $this->_scripts[] = $js;
	}
	public function addMeta($name, $content) 
	{
		$this->_meta[$name] = $content; 
	}
}